package com.winner.data.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;

import com.winner.data.exception.R;

/**
 * @Author wangxinle5
 * @since 2025-07-15
 */
@RestController
@RequestMapping("/")
public class RetryController extends BaseController {

    // 通过代理调用, 如果在当前方法内调用, retry不会生效
    @Autowired
    private ProxyClass proxyClass;

    /**
     * http://localhost:8080/retry
     *
     * @return 结果
     */
    @GetMapping("/retry")
    public R retry() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        try {
            proxyClass.callThird();
        } catch (RestClientException e) {
            stopWatch.stop();
            System.out.println(stopWatch.getTotalTimeSeconds());
            throw new RuntimeException(e);
        }
        return R.success();
    }
}
